<?
	require_once "../../_func/__Global.php";
	require_once "../../_func/__Local.php";
	require_once "../../_func/__MysqlFunc.php";
	require_once "../../_func/_CodeFunc.php";
?>
<?
	$db = GetDefaultConnection();
	$seq = $param->getString('seq');

	$queryarry = array(
		'ORDER_SEQ' => $seq,
	);

	$query=makeWhereQry($queryarry);

	if ($query != "")
		$where .= " and ". $query;
 
	$sql = sprintf("SELECT TRADE_DATE, TRADE_NUMBER, TRADE_PRICE, ORDER_WEIGHT2 "
					.", (select FARM_NAME FROM TB_FARM WHERE FARM_SEQ=c.FARM_SEQ) as FARM_NAME "
					.", (select JBNH_NAME FROM TB_JBNH WHERE JBNH_SEQ=a.JBNH_SEQ) as JBNH_NAME "
					.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='A' AND CODE_CODE1=a.ORDER_ITEM1 AND CODE_CODE2=0) as ITEM1_NAME "
					.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='A' AND CODE_CODE1=a.ORDER_ITEM1 AND CODE_CODE2=a.ORDER_ITEM2) as ITEM2_NAME "
					.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='B' AND CODE_CODE1=a.ORDER_GRADE1 AND CODE_CODE2=a.ORDER_GRADE2) as GRADE2_NAME "
					.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='B' AND CODE_CODE1=a.ORDER_STANDARD1 AND CODE_CODE2=a.ORDER_STANDARD2) as STANDARD2_NAME "
					.", (select CODE_NAME FROM TB_CODE WHERE CODE_TYPE='C' AND CODE_CODE1=a.ORDER_DESTINATION1 AND CODE_CODE2=0) as ORDER_DESTINATION1_NAME "
					." FROM TB_ORDER a inner join TB_TRADE b on a.ORDER_CODE=b.ORDER_CODE inner join TB_PRODUCT c on b.PRODUCT_SEQ=c.PRODUCT_SEQ where ORDER_SEQ=%d", $seq);
	$list = $db->queryList($sql);

	if ($list != null)
	{
		$row = & $list->next();
		$trade_date = $row->getString('TRADE_DATE');
		$jbnh_name = $row->getString('JBNH_NAME');
		$order_weight2 = $row->getString('ORDER_WEIGHT2');
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{상호명들어가는부분} 출하통지서</title>
</head>

<body>
<center>
<table cellpadding="0" cellspacing="0" border="0" width="800" style="font-family:Malgun gothic; line-height:120%; font-size:17px">
	<tr>
		<td height="40" style="text-align:center; font-size:25px; font-weight:bold;">
			<span style="border-bottom:3px double; padding:0 10px 6px;">농산물 출하통지서</span>
		</td>
	</tr>
	<tr>
		<td height="30" style="text-align:center; padding:0 0 10px 0">(출 하 농 가 용)</td>
	</tr>
	<tr>
		<td align="left">
			<table cellpadding="5" cellspacing="1" border="1" width="100%" style="border-collapse:collapse; border:2px solid #333333; padding:0; margin:0" >
				<colgroup>
					<col width="30px" />
					<col width="120px" />
					<col width="315px" />
					<col width="30px" />
					<col width="120px" />
					<col width="315px" />
				</colgroup>
				<tr>
					<td rowspan="5">공급자</td>
					<td style="text-align:center; letter-spacing:13px; text-indent:12px;">상 호</td>
					<td style="text-align:center;">농협중앙회 전북지역본부</td>
					<td rowspan="5">공급받는자</td>
					<td style="text-align:center; letter-spacing:13px; text-indent:12px;">상 호</td>
					<td></td>
				</tr>
				<tr>
					<td style="text-align:center;">출하일자</td>
					<td style="text-align:center;">
						<span></span>
						<span style="padding-left:30px;"><?=date_format(new DateTime($trade_date),'Y')?>년</span>
						<span style="padding-left:60px;"><?=date_format(new DateTime($trade_date),'m')?>월</span>
						<span style="padding-left:60px;"><?=date_format(new DateTime($trade_date),'d')?>일</span>
					</td>
					<td style="text-align:center;">검수일자</td>
					<td style="text-align:center;">
						<span style="margin:0">201</span>
						<span style="padding-left:30px; margin:0">년</span>
						<span style="padding-left:60px; margin:0">월</span>
						<span style="padding-left:60px; margin:0">일</span>
					</td>
				</tr>
				<tr>
					<td style="text-align:center;">전화번호</td>
					<td style="text-align:center;">063-240-3142</td>
					<td style="text-align:center; letter-spacing:8px; text-indent:8px;">검수자</td>
					<td style="text-align:center;">
						<span>직</span>
						<span style="padding:0 80px;">성명</span><img src="../img/in.gif" />
					</td>
				</tr>
				<tr>
					<td style="text-align:center; letter-spacing:15px; text-indent:12px;">FAX</td>
					<td style="text-align:center;">063-240-3150</td>
					<td style="text-align:center;">전화번호</td>
					<td></td>
				</tr>
				<tr>
					<td style="text-align:center;">공급조합</td>
					<td style="text-align:right;">농업협동조합 <img src="../img/in.gif" /></td>
					<td style="text-align:center; letter-spacing:8px; text-indent:8px;">휴대폰</td>
					<td></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td height="50" align="left" style="font-family:batang; font-size:22px;">아래와 같이 농산물을 출하, 검수 하였기에 통지합니다.</td>
	</tr>
	<tr>
		<td height="50" align="left">◆ 출 하 내 역</td>
	</tr>
	<tr>
		<td style="font-size:14px; line-height:100%;vertical-align:top;">
				<table cellpadding="5" cellspacing="1" border="1" width="100%" style="border-collapse:collapse; border:2px solid #333333;">
					<tr>
						<th height="25" bgcolor="#ebebeb">생산자</th>
						<th bgcolor="#ebebeb">품목명</th>
						<th bgcolor="#ebebeb">산년</th>
						<th bgcolor="#ebebeb">단량</th>
						<th bgcolor="#ebebeb">등급</th>
						<th bgcolor="#ebebeb">수량</th>
						<th bgcolor="#ebebeb">단가</th>
						<th bgcolor="#ebebeb">금액</th>
						<th bgcolor="#ebebeb">기타<br />공제</th>
						<th bgcolor="#ebebeb">반품</th>
						<th bgcolor="#ebebeb">비고</th>
					</tr>
<?
	$list = $db->queryList($sql)
?>
<?
	$i=0;
	$tot1=0;
	$tot2=0;
	if ($list->getLength() != 0)
	{
		while ($list->hasNext())
		{
			$row = & $list->next();
			$trade_number = $row->getNumber('TRADE_NUMBER');
			$trade_price = $row->getNumber('TRADE_PRICE');
			$farm_name = $row->getString('FARM_NAME');
			$item1_name = $row->getString('ITEM1_NAME');
			$item2_name = $row->getString('ITEM2_NAME');
			$grade2_name = $row->getString('GRADE2_NAME');
			$standard2_name = $row->getString('STANDARD2_NAME');
			$tnum = $trade_number/$order_weight2;
			$tprice = $tnum*$trade_price;
			$tot1 += $tnum;
			$tot2 += $tprice;
?>
					<tr>
						<td height="20"><?=$farm_name?></td>
						<td><?=$item2_name?></td>
						<td>-</td>
						<td>-</td>
						<td><?=$grade2_name?></td>
						<td><?=number_format($tnum)?>BOX</td>
						<td><?=number_format($trade_price)?></td>
						<td><?=number_format($tprice)?></td>
						<td>-</td>
						<td>-</td>
						<td>-</td>
					</tr>
<?
			$i+=1;
		}
	}

	for($i;$i<10;$i++)
	{
?>
					<tr>
						<td height="20"></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
					</tr>
<?
	}
?>
					<tr>
						<td colspan="11" height="1" style="border-bottom:2px double; padding:0;"></td>
					</tr>
					<tr>
						<td height="25">합계</td>
						<td>-</td>
						<td>-</td>
						<td>-</td>
						<td>-</td>
						<td><?=number_format($tot1)?>BOX</td>
						<td>-</td>
						<td><?=number_format($tot2)?></td>
						<td>-</td>
						<td>-</td>
						<td>-</td>
					</tr>
				</table>
		</td>
	</tr>
	<tr>
		<td style="padding-top:20px;">
			<table cellpadding="5" cellspacing="1" border="1" width="100%" style="border-collapse:collapse; border:2px solid #333333;">
				<colgroup>
					<col width="60px" />
					<col width="100px" />
					<col width="70px" />
					<col width="145px" />
					<col width="60px" />
					<col width="120px" />
					<col width="195px" />
				<tr>
					<td rowspan="2" colspan="2">파 레 트</td>
					<td>출고</td>
					<td align="right">매</td>
					<td rowspan="2">출하<br />차량</td>
					<td style="text-align:center; letter-spacing:8px; text-indent:8px;">기사명</td>
					<td></td>
				</tr>
				<tr>
					<td>회수</td>
					<td align="right">매</td>
					<td>차량번호</td>
					<td></td>
				</tr>
				<tr>
					<td rowspan="3">출하<br />농협</td>
					<td style="text-align:center; letter-spacing:8px; text-indent:8px;">농협명</td>
					<td colspan="2"><?=$jbnh_name?></td>
					<td rowspan="3">송금<br />농협</td>
					<td colspan="2">농협중앙회 전북지역본부</td>
				</tr>
				<tr>
					<td>전화번호</td>
					<td colspan="2"></td>
					<td style="text-align:center; letter-spacing:8px; text-indent:8px;">환코드</td>
					<td><strong>501</strong></td>
				</tr>
				<tr>
					<td style="text-align:center; letter-spacing:12px; text-indent:10px;">주 소</td>
					<td colspan="2">시</td>
					<td>계좌번호</td>
					<td><strong>301-0079-7748-11</strong></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</center>
</body>
</html>
